package cn.sjlink.config;
import cn.sjlink.util.Result;
import cn.sjlink.util.ResultCode;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ExceptionAspect {

    @Around("@annotation(ResultHandler)")
    public Object ExceptionHandler(ProceedingJoinPoint joinPoint) throws Throwable{
        Object proceed = null;
        try {
            proceed = joinPoint.proceed();
        } catch (BusinessException e) {
            return new Result(e.getMsg());
        } catch (LoginException e){
            return new Result(ResultCode.LOGIN,e.getMessage());
        }
        catch (Exception e) {
            return new Result(false,"服务器异常，请稍后再试");
        }
        return proceed;
    }
}
